home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / attachCurveTangent.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.7 KB  |  127 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Jan 12, 1998
  22. //  Author:        mgr 
  23. //
  24. //  Description:
  25. //      The attachCurveTangent() procedure takes the selected two curves and 
  26. //        creates a one span curve between them that is tangent to the end of 
  27. //      curve1 and the start of curve2. The result will always be at least a 
  28. //      degree 3 curve. If you don't want to attach the curves then call this 
  29. //      proc with $doAttach = 0.
  30. //
  31. //  Input Arguments:
  32. //      $doAttach - if 1 attach results otherwise just create new curve
  33. //
  34. //  Return Value:
  35. //      String.
  36. //
  37.  
  38. global proc string attachCurveTangent( int $doAttach )
  39. {
  40.     global int $gSelectNurbsCurvesBit;
  41.     string $curvesList[] = `filterExpand -ex true -sm $gSelectNurbsCurvesBit`;
  42.  
  43.     int $numCurves = size($curvesList);
  44.     if ( $numCurves < 2 )
  45.     {
  46.         error("Need to select two curves.");
  47.         return "";
  48.     }
  49.  
  50.     // get the last 2 cvs on the first curve and the first 2 cvs on the 
  51.     // second curve
  52.     //
  53.     int $degree = eval("getAttr " + $curvesList[0] + ".degree");
  54.     int $numSpans = eval("getAttr " + $curvesList[0] + ".spans");
  55.     int $numCVs1 = $degree + $numSpans;
  56.     $degree = eval("getAttr " + $curvesList[1] + ".degree");
  57.     $numSpans = eval("getAttr " + $curvesList[1] + ".spans");
  58.     int $numCVs2 = $degree + $numSpans;
  59.     if ( $numCVs1 < 2 || $numCVs2 < 2 )
  60.     {
  61.         error("Each selected curve must have at least two cvs.");
  62.         return "";
  63.     }
  64.  
  65.     int $lastCV = $numCVs1 - 1;
  66.     float $cvLastCurve1[] = `getAttr ($curvesList[0] + ".cp[" + $lastCV + "]")`;
  67.     $lastCV--;
  68.     float $cv2ndLastCurve1[] = `getAttr ($curvesList[0] + ".cp[" + $lastCV + "]")`;
  69.     float $cvOneCurve2[] = `getAttr ($curvesList[1] + ".cp[0]")`;
  70.     float $cvTwoCurve2[] = `getAttr ($curvesList[1] + ".cp[1]")`;
  71.  
  72.     // this is the vector between the two cvs on the first curve
  73.     //
  74.     float $vector[3];
  75.     $vector[0] = $cvLastCurve1[0] - $cv2ndLastCurve1[0];
  76.     $vector[1] = $cvLastCurve1[1] - $cv2ndLastCurve1[1];
  77.     $vector[2] = $cvLastCurve1[2] - $cv2ndLastCurve1[2];
  78.  
  79.     // calculate a cv on the line between the two end cvs so that it will 
  80.     // be tangent
  81.     //
  82.     float $cvNew1[3];
  83.     $cvNew1[0] = $cvLastCurve1[0] + $vector[0];
  84.     $cvNew1[1] = $cvLastCurve1[1] + $vector[1];
  85.     $cvNew1[2] = $cvLastCurve1[2] + $vector[2];
  86.     
  87.     // this is the vector between the two cvs on the second curve
  88.     //
  89.     float $vector[3];
  90.     $vector[0] = $cvOneCurve2[0] - $cvTwoCurve2[0];
  91.     $vector[1] = $cvOneCurve2[1] - $cvTwoCurve2[1];
  92.     $vector[2] = $cvOneCurve2[2] - $cvTwoCurve2[2];
  93.  
  94.     // calculate a cv on the line between the two start cvs so that it will 
  95.     // be tangent
  96.     //
  97.     float $cvNew2[3];
  98.     $cvNew2[0] = $cvOneCurve2[0] + $vector[0];
  99.     $cvNew2[1] = $cvOneCurve2[1] + $vector[1];
  100.     $cvNew2[2] = $cvOneCurve2[2] + $vector[2];
  101.  
  102.     // create the degree 3 curve
  103.     //
  104.     string $resultCurve = eval("curve -p " + $cvLastCurve1[0] + " " + $cvLastCurve1[1] + " " + $cvLastCurve1[2] + " -p " + $cvNew1[0] + " " + $cvNew1[1] + " " + $cvNew1[2] + " -p " + $cvNew2[0] + " " + $cvNew2[1] + " " + $cvNew2[2] + " -p " + $cvOneCurve2[0] + " " + $cvOneCurve2[1] + " " + $cvOneCurve2[2] + " -k 0 -k 0 -k 0 -k 1 -k 1 -k 1");
  105.  
  106.     // attach all 3 curves if required
  107.     //
  108.     if ( $doAttach == 1 )
  109.     {
  110.         // attach curve1 to the new curve
  111.         //
  112.         string $attachedCurve[] = eval("attachCurve -ch 0 -rpo 0 -kmk 1 " + $curvesList[0] + " " + $resultCurve);
  113.  
  114.         // the tangent curve is no longer needed
  115.         //
  116.         delete $resultCurve;
  117.  
  118.         // attach curve2 to the previously attached curves
  119.         //
  120.         $attachedCurve = eval("attachCurve -ch 0 -rpo 1 -kmk 1 " + $attachedCurve[0] + " " + $curvesList[1]);
  121.         $resultCurve = $attachedCurve[0];
  122.     }
  123.  
  124.     select -r $resultCurve;
  125.     return $resultCurve;
  126. }
  127.